﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TheControllerRisk.Settings;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;

namespace RiskMan.DataClass.Models
{
    /// <summary>
    /// Модель данных для строки Risk Manager
    /// </summary>
    [Serializable]
    public class RMItem : INotifyPropertyChanged, ISerializable
    {
        public bool IsShowMessage = false;

        #region private

        private bool _considerVMND;
        private double _comisBlock;
        private bool _runComicBlock;
        private bool _checked = false;
        private bool _isRun = false;
        private String _Account;
        private List<String> _AccountList;
        private String _ClientCode;
        private List<String> _ClientCodeList;
        private bool _isBlock = false;
        private int _kGO;
        private String _Variable;
        private List<String> _VariableList = new List<string>( ) { cfg.UNKNOWN, cfg.MODE_0, cfg.MODE_1, cfg.MODE_2 };
        private int _Stage;
        private int _Unblock;
        private double _DrowDown;
        private String _TypeRasch;
        private List<String> _TypeRaschList = new List<string>( ) { cfg.UNKNOWN, cfg.PERSENT, cfg.RUB };
        private double _profitBlock;
        private double _reductionGO;
        private double _reductionGOEvening;
        private double _TimeStrartreductionGOEvening;

        private String _TypeEnterLimite;
        private List<String> _TypeEnterLimiteList = new List<string>( ) { cfg.UNKNOWN, "Обычный", "Трейлинг профит" };

        private string _status;
        private int _ID;
        private DateTime _timeSend;

        #endregion

        #region public

        public bool ConsiderVMND
        {
            get { return _considerVMND; }
            set { _considerVMND = value; }
        }
        public double ComisBlock
        {
            get { return _comisBlock; }
            set { _comisBlock = value; }
        }
        public bool RunComicBlock
        {
            get { return _runComicBlock; }
            set { _runComicBlock = value; }
        }
        public bool Check
        {
            get { return _checked; }
            set
            {
                if ( _checked != value )
                {
                    _checked = value;
                    RaisePropertyChanged( "Check" );
                }
            }
        }
        public bool isRun
        {
            get { return _isRun; }
            set
            {
                if ( _isRun != value )
                {
                    _isRun = value;
                    RaisePropertyChanged( "isRun" );
                }
            }
        }
        public bool IsBlock
        {
            get { return _isBlock; }
            set
            {
                if ( _isBlock != value )
                {
                    _isBlock = value;
                    RaisePropertyChanged( "IsBlock" );
                }
            }
        }
        public String Account
        {
            get { return _Account; }
            set
            {
                if ( _Account != value )
                {
                    _Account = value;
                    RaisePropertyChanged( "Account" );
                }
            }
        }
        public double ProfitBlock
        {
            get { return _profitBlock; }
            set
            {
                if (_profitBlock != value)
                {
                    _profitBlock = value;
                    RaisePropertyChanged("ProfitBlock");
                }
            }
        }
        public List<String> AccountList
        {
            get { return _AccountList; }
            set
            {
                if ( _AccountList != value )
                {
                    _AccountList = value;
                    RaisePropertyChanged( "AccountList" );
                }
            }
        }
        public String ClientCode
        {
            get { return _ClientCode; }
            set
            {
                if ( _ClientCode != value )
                {
                    _ClientCode = value;
                    RaisePropertyChanged( "ClientCode" );
                }
            }
        }
        public List<String> ClientCodeList
        {
            get { return _ClientCodeList; }
            set
            {
                if ( _ClientCodeList != value )
                {
                    _ClientCodeList = value;
                    RaisePropertyChanged( "ClientCodeList" );
                }
            }
        }
        public int kGO
        {
            get { return _kGO; }
            set
            {
                if ( _kGO != value )
                {
                    _kGO = value;
                    RaisePropertyChanged( "kGO" );
                }
            }
        }
        public String Variable
        {
            get { return _Variable; }
            set
            {
                if ( _Variable != value )
                {
                    _Variable = value;
                    RaisePropertyChanged( "Variable" );
                }
            }
        }
        public List<String> VariableList
        {
            get { return _VariableList; }
            set
            {
                if ( _VariableList != value )
                {
                    _VariableList = value;
                    RaisePropertyChanged( "VariableList" );
                }
            }
        }
        public int Stage
        {
            get { return _Stage; }
            set
            {
                if ( _Stage != value )
                {
                    _Stage = value;
                    RaisePropertyChanged( "Stage" );
                }
            }
        }
        public int Unblock
        {
            get { return _Unblock; }
            set
            {
                if ( _Unblock != value )
                {
                    _Unblock = value;
                    RaisePropertyChanged( "Unblock" );
                }
            }
        }
        public double DrowDown
        {
            get { return _DrowDown; }
            set
            {
                if ( _DrowDown != value )
                {
                    _DrowDown = value;
                    RaisePropertyChanged( "DrowDown" );
                }
            }
        }

        /// <summary>
        /// Пониженное ГО, указывается в процентах от базавого не дневную сессию
        /// </summary>
        public double ReductionGO
        {
            get { return _reductionGO; }
            set
            {
                if (_reductionGO != value)
                {
                    _reductionGO = value;
                    RaisePropertyChanged("ReductionGO");
                }
            }
        }

        /// <summary>
        /// Пониженное ГО, указывается в процентах от базавого на вечернюю сессию
        /// </summary>
        public double ReductionGOEvening
        {
            get { return _reductionGOEvening; }
            set
            {
                if (_reductionGOEvening != value)
                {
                    _reductionGOEvening = value;
                    RaisePropertyChanged("ReductionGOEvening");
                }
            }
        }

        /// <summary>
        /// Время когда начинает действовать пониженное ГО для вечерней сессии.
        /// </summary>
        public double TimeStrartreductionGOEvening
        {
            get { return _TimeStrartreductionGOEvening; }
            set
            {
                if (_TimeStrartreductionGOEvening != value)
                {
                    _TimeStrartreductionGOEvening = value;
                    RaisePropertyChanged("TimeStrartreductionGOEvening");
                }
            }
        }

        public string TypeRasch
        {
            get { return _TypeRasch; }
            set
            {
                if ( _TypeRasch != value )
                {
                    _TypeRasch = value;
                    RaisePropertyChanged( "TypeRasch" );
                }
            }
        }
        public List<string> TypeRaschList
        {
            get { return _TypeRaschList; }
            set
            {
                if ( _TypeRaschList != value )
                {
                    _TypeRaschList = value;
                    RaisePropertyChanged( "TypeRaschList" );
                }
            }
        }
        public String TypeEnterLimite
        {
            get { return _TypeEnterLimite; }
            set
            {
                if ( _TypeEnterLimite != value )
                {
                    _TypeEnterLimite = value;
                    RaisePropertyChanged( "TypeEnterLimite" );
                }
            }
        }
        public List<String> TypeEnterLimiteList
        {
            get { return _TypeEnterLimiteList; }
            set
            {
                if ( _TypeEnterLimiteList != value )
                {
                    _TypeEnterLimiteList = value;
                    RaisePropertyChanged( "TypeEnterLimiteList" );
                }
            }
        }

        /// <summary>
        /// Статус отправленной транзакции 
        /// </summary>
        public String Status
        {
            get { return _status; }
            set
            {
                if (_status != value)
                {
                    _status = value;
                    RaisePropertyChanged("Status");
                }
            }
        }

        /// <summary>
        /// ID отправленной транзакции
        /// </summary>
        public int ID
        {
            get { return _ID; }
            set
            {
                if (_ID != value)
                {
                    _ID = value;
                    RaisePropertyChanged("ID");
                }
            }
        }

        /// <summary>
        /// Время отправленной транзакции
        /// </summary>
        public DateTime TimeSend
        {
            get { return _timeSend; }
            set
            {
                if (_timeSend != value)
                {
                    _timeSend = value;
                    RaisePropertyChanged("TimeSend");
                }
            }
        }

        #endregion

        #region event PropertyChangedEventHandler

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged ( string propertyName )
        {
            var handler = PropertyChanged;
            if ( handler != null )
            {
                handler( this, new PropertyChangedEventArgs( propertyName ) );
            }
        }

        #endregion

        public RMItem ( ) { }

        public RMItem ( SerializationInfo info, StreamingContext context )
        {
            ConsiderVMND = info.GetBoolean( "ConsiderVMND" );
            ComisBlock = info.GetDouble( "ComisBlock" );
            RunComicBlock = info.GetBoolean( "RunComicBlock" );
            Check = info.GetBoolean( "Check" );
            isRun = info.GetBoolean( "isRun" );
            IsBlock = info.GetBoolean( "IsBlock" );
            ProfitBlock = info.GetDouble("ProfitBlock");

            Account = info.GetString( "Account" );
            AccountList = ( List<String> ) info.GetValue( "AccountList", typeof( List<String> ) );

            ClientCode = info.GetString( "ClientCode" );
            ClientCodeList = ( List<String> ) info.GetValue( "ClientCodeList", typeof( List<String> ) );

            kGO = info.GetInt32( "kGO" );

            Variable = info.GetString( "Variable" );
            VariableList = ( List<String> ) info.GetValue( "VariableList", typeof( List<String> ) );

            Stage = info.GetInt32( "Stage" );
            Unblock = info.GetInt32( "Unblock" );
            DrowDown = info.GetDouble( "DrowDown" );
            ReductionGO = info.GetDouble("ReductionGO");
            ReductionGOEvening = info.GetDouble("ReductionGOEvening");
            TimeStrartreductionGOEvening = info.GetDouble("TimeStrartreductionGOEvening");

            TypeRasch = info.GetString( "TypeRasch" );
            TypeRaschList = ( List<String> ) info.GetValue( "TypeRaschList", typeof( List<String> ) );

            TypeEnterLimite = info.GetString( "TypeEnterLimite" );
            TypeEnterLimiteList = ( List<String> ) info.GetValue( "TypeEnterLimiteList", typeof( List<String> ) );

            Status = info.GetString("Status");
            ID = info.GetInt32("ID");
            TimeSend = info.GetDateTime("TimeSend");
        }

        public void GetObjectData ( SerializationInfo info, StreamingContext context )
        {
            info.AddValue( "ConsiderVMND", ConsiderVMND );
            info.AddValue( "ComisBlock", ComisBlock );
            info.AddValue( "RunComicBlock", RunComicBlock );
            info.AddValue( "Check", Check );
            info.AddValue( "isRun", isRun );
            info.AddValue( "IsBlock", IsBlock );
            info.AddValue( "Account", Account );
            info.AddValue( "AccountList", AccountList );
            info.AddValue( "ClientCode", ClientCode );
            info.AddValue( "ClientCodeList", ClientCodeList );
            info.AddValue( "kGO", kGO );
            info.AddValue( "Variable", Variable );
            info.AddValue( "VariableList", VariableList );
            info.AddValue( "Stage", Stage );
            info.AddValue( "Unblock", Unblock );
            info.AddValue( "DrowDown", DrowDown );
            info.AddValue("ReductionGO", ReductionGO);
            info.AddValue("ReductionGOEvening", ReductionGOEvening);
            info.AddValue("TimeStrartreductionGOEvening", TimeStrartreductionGOEvening);
            info.AddValue( "TypeRasch", TypeRasch );
            info.AddValue( "TypeRaschList", TypeRaschList );
            info.AddValue( "TypeEnterLimite", TypeEnterLimite );
            info.AddValue( "TypeEnterLimiteList", _TypeEnterLimiteList );
            info.AddValue("ProfitBlock", ProfitBlock);
            info.AddValue("Status", Status);
            info.AddValue("ID", ID);
            info.AddValue("TimeSend", TimeSend);
        }
    }
}